<%--
    file: module.jsp
--%>
<%@page import="java.util.List"%>
<%@page 
    contentType="text/html" pageEncoding="UTF-8"
    %>

<%
    String message = "";
    if (null != request.getAttribute("msg")) {
        message = request.getAttribute("msg").toString();
    }
    String scuccess = "";
    if (null != request.getAttribute("scuccess")) {
        scuccess = request.getAttribute("scuccess").toString();
    }


    String regscuccess = "";
    if (null != request.getAttribute("regscuccess")) {
        regscuccess = request.getAttribute("regscuccess").toString();
    }

    List modules = null;
    if (null != request.getAttribute("modules")) {
        modules = (List) request.getAttribute("modules");
    }

    List mymoduleids = null;
    if (null != request.getAttribute("moduleids")) {
        mymoduleids = (List) request.getAttribute("moduleids");
    }
    
    List mytutorialids = null;
    if (null != request.getAttribute("tutorialids")) {
        mytutorialids = (List) request.getAttribute("tutorialids");
    }

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="/StudentClientWeb/img/style.css" />
        <title>Module Search System</title>
    </head>

    <body>
        <div id="page">

            <div id="header">
                <h1>Module Search System</h1>
                <h2>Web-based client application, Module Search System for Student</h2>

            </div>
            <div id="bar">
                <div class="link"><a href="module">Module Search</a></div>
                <div class="link"><a href="mymodules">My Modules</a></div>
                <div class="link"><a href="profile">Profile</a></div>
                <div class="link"><a href="logout">Logout</a></div>
            </div>

            <% if ("false" == scuccess) {%>
            <div class="notify notify-red"><span class="symbol icon-error"></span> <%= message%> </div>
            <% }%>
            <div class="contentTitle"><h1>Module Search</h1></div>
            <div class="contentText">

                <div class="notify"><span class="symbol icon-info"></span> Search for Modules by specifying the module code or keywords in the module title !</div>

                <form action="module">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td style="width:120px"><input name="searchtype" type="radio" value="mcode" checked="checked"> Module Code</td>
                            <td style="width:100px"><input type="text" name="modulecode" style="width:100px"/></td>
                            <td style="text-align:center; width:70px">Or</td>
                            <td style="width:120px"><input name="searchtype" type="radio" value="mtitle"> Module Title</td>
                            <td style="width:120px"><input type="text" name="moduletitle" style="width:120px"/></td>
                            <td><input type="hidden" name="reqfunction" value="modulesearch"/></td>
                            <td style="text-align:right"><input type="submit" value="Search"></td>
                        </tr>
                    </table>			

                </form>	
            </div>
            <div class="contentTitle"><h1>Modules</h1></div>
            <div class="contentText">

                <% if ("false" == regscuccess) {%>
                <div class="notify notify-red"><span class="symbol icon-error"></span> <%= message%> </div>
                <% } else if ("false" == regscuccess) {%>
                <div class="notify notify-green"><span class="symbol icon-tick"></span> <%= message%></div>
                <% }%>
                <table class="csstable" cellspacing="0" cellpadding="0">
                    <tr>
                        <th scope="col" style="width: 120px">Module</th>
                        <th scope="col" style="width: 120px">Synopsis</th>
                        <th scope="col" style="width: 180px">Lecture</th>
                        <th scope="col">Tutorials</th>
                    </tr>
                    <% if ("true" == scuccess) {
                            for (Object m : modules) {
                                List mod = (List) m;
                                boolean reg = false;
                                if (null != mymoduleids && mymoduleids.contains(mod.get(0))) {
                                    reg = true;
                                }
                    %>
                    <tr>
                        <td><p><%=mod.get(1)%></p><p><%=mod.get(2)%></p>
                            <% if(reg){%>
                            <p>[Registered]</p>
                            <% } else {%>
                            <a href="module?reqfunction=modulereg&moduleid=<%=mod.get(0)%>&timeslot=<%=mod.get(5)%>">[Register]</a>
                            <% }%>
                        </td>
                        <td><p><%=mod.get(3)%></p></td>
                        <td><p><%=mod.get(4)%></p><p><%=mod.get(5)%></p><p><%=mod.get(6)%></p></td>
                        <td>
                            <%
                                List tuts = (List) mod.get(7);
                                if (null != tuts && !tuts.isEmpty()) {
                                    for (Object t : tuts) {
                                        List tut = (List) t;
                                        
                                        boolean regtut = false;
                                        if (null != mytutorialids && mytutorialids.contains(tut.get(0))) {
                                            regtut = true;
                                        }
                            %>   
                            <p><%=tut.get(1)%></p>
                            <p><%=tut.get(2)%></p>
                            <p><%=tut.get(3)%></p>
                            <p><%=tut.get(4)%></p>
                            
                            <% if(!regtut && reg){%>
                            <a href="module?reqfunction=tutorialreg&moduleid=<%=mod.get(0)%>&mreg=<%=reg%>&tutorialid=<%=tut.get(0)%>&timeslot=<%=tut.get(3)%>">[Register]</a>
                            
                            <% } else if(reg) {%>
                            <p>[Registered]</p>
                            <% }%>
                            
                            <%}
                            }%>
                        </td>
                    </tr>
                    <%}
                    } else {%>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <%}%>
                </table>


                <% if (null != scuccess && "true" == scuccess) {%>
                <div class="notify">
                    <span class="symbol icon-info"></span>
                    Register Module by click link Register under module title, register Tutorial by click link Register under Tutorial information.
                    If related Module haven't register, will register both Module and Tutorial together !
                </div>
                <% }%>

            </div> 
        </div>
        <div id="footer"><a href="http://www.culin.net">web development</a> by <a href="http://www.cuilin.com">Cui Lin</a></div>
    </body>
</html>